﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;

namespace ECommerce.DAO.Cache.Contabilidad.Carritos
{
    public static class Carrito
    {
        public static ECommerce.Model.Contabilidad.Carritos.Carrito GetCarritoById(Int32 Id)
        {
            ECommerce.Model.Contabilidad.Carritos.Carrito Carrito = new ECommerce.Model.Contabilidad.Carritos.Carrito();
            try
            {
                Carrito = (ECommerce.Model.Contabilidad.Carritos.Carrito)HttpRuntime.Cache["Carrito-" + Id];
            }
            catch (Exception ex)
            {
                Carrito = null;
            }
            if (Carrito != null && Carrito.Id == 0)
                Carrito = null;
            return Carrito;
        }
        public static int SetCarrito(ECommerce.Model.Contabilidad.Carritos.Carrito Carrito)
        {
            try
            {
                HttpRuntime.Cache.Insert("Carrito-" + Carrito.Id.ToString(), Carrito);
            }
            catch (Exception ex)
            {
            }
            return Carrito.Id;
        }
        public static int DelCarrito(ECommerce.Model.Contabilidad.Carritos.Carrito Carrito)
        {
            try
            {
                HttpRuntime.Cache.Remove("Carrito-" + Carrito.Id.ToString());
            }
            catch (Exception ex)
            {
            }
            return Carrito.Id;
        }


        public static ECommerce.Model.Contabilidad.Carritos.ItemCarrito[] GetItemsCarritoByIdCarrito(int IdCarrito)
        {
            ECommerce.Model.Contabilidad.Carritos.ItemCarrito[] ItemsCarrito;
            try
            {
                ItemsCarrito = (ECommerce.Model.Contabilidad.Carritos.ItemCarrito[])HttpRuntime.Cache["ItemsCarrito-" + IdCarrito.ToString()];
            }
            catch (Exception ex)
            {
                ItemsCarrito = null;
            }
            if (ItemsCarrito != null)
                if (ItemsCarrito.Length == 0)
                    ItemsCarrito = null;
            return ItemsCarrito;
        }

        public static int SetItemsCarrito(ECommerce.Model.Contabilidad.Carritos.Carrito[] ItemsCarrito, int IdCarrito)
        {
            try
            {
                HttpRuntime.Cache.Insert("ItemsCarrito-" + IdCarrito.ToString(), ItemsCarrito);
            }
            catch (Exception ex)
            {
            }
            return IdCarrito;
        }
        public static int DelItemsCarrito(int IdCarrito)
        {
            try
            {
                HttpRuntime.Cache.Remove("ItemsCarrito-" + IdCarrito.ToString());
            }
            catch (Exception ex)
            {
            }
            return IdCarrito;
        }


        public static ECommerce.Model.Contabilidad.Carritos.Carrito[] GetCarritosDelSistema()
        {
            throw new NotImplementedException();
        }

        public static ECommerce.Model.Contabilidad.Carritos.Carrito[] GetCarritosByProductoId(int IdProducto)
        {
            throw new NotImplementedException();
        }
    }
}
